<?php 
	
class course {

	private $idGrandPrix;
	private $idPilote;   
	private $tempCourse; 
	
	
	public function __construct()
	{
		$this->db = new myPdo ;
		$req="set names 'UTF8'";
		$this->db->exec($req);
	}
	
	// SETTEURS
	public function setIdPilote($idPilote) 
	{
		$this->idPilote = $idPilote ;
	}
	public function setIdGrandPrix($idGrandPrix) 
	{
		$this->idGrandPrix = $idGrandPrix  ;
	}
	public function setTempCourse($tempCourse) 
	{
		$this->tempCourse = $tempCourse ;
	}
	
	// GETTEURS
	public function getIdPilote() 
	{
		return $this->idPilote;
	}
	public function getIdGrandPrix() 
	{
		return $this->idGrandPrix;
	}
	public function getTempCourse() 
	{
		return $this->tempCourse;
	}

	// METHODES
	public function getResultats()
	{
		$r = "	SELECT GPNUM, PILNUM, TEMPSCOURSE 
				FROM course 
				WHERE GPNUM = $this->idGrandPrix 
				ORDER BY TEMPSCOURSE ; " ;
		
		$resu = $this->db->query($r) ;
		$tablo = null ;
		while ($ligne = $resu->fetch(PDO::FETCH_OBJ))
		{
			$tablo[] = $ligne ;
		}
		return $tablo ;
	}
	
	public function ajouterCourse()
	{
		$r = "	INSERT INTO course(GPNUM,PILNUM,TEMPSCOURSE)
				VALUES($this->idGrandPrix,$this->idPilote,'$this->tempCourse') ; " ;
		echo $r ;
		$resu = $this->db->query($r) ;
	}
	
	public function supprimerCourse()
	{
		$r = "	DELETE FROM course WHERE GPNUM=$this->idGrandPrix AND PILNUM=$this->idPilote ; " ;
		echo $r ;
		$resu = $this->db->query($r) ;
	}

}
?>